//
//  stdThread.cpp
//  learnC++
//
//  Created by liuzhibing on 2018/7/18.
//  Copyright © 2018年 yunfan.com. All rights reserved.
//

#include "stdThread.hpp"

void threadTask(){
    
    std::cout << "XXXXXXXXXXXX";
    
    sleep(3);
}

ThreadClass::ThreadClass(){
    
}

ThreadClass::~ThreadClass(){
    
}

void* ThreadClass::printSomethig(void *param){
    std::cout << "This is print" << std::endl;
    
    sleep(3);
    
    /*
    char tem[] = "this is";
    pthread_exit(tem);//杀死线程，后面的代码不会执行

    printf("LLLLL");
    sleep(3);
    */
    return NULL;
}

void ThreadClass::creatThread(){
    std::thread t(threadTask);
    t.join();//阻塞当前线程
    
    printf("kkkkk");
    
}

void ThreadClass::creatP_thread(){
    
    pthread_create(&m_id, NULL, ThreadClass::printSomethig, this);

    if (0) {
        int res = pthread_join(m_id, NULL);//阻塞当前线程
        
        if (res == 0) {
            
            printf("YES\n");
        }else{
            printf("error");
        }
    }else{
        
        pthread_detach(m_id);
    }
    
    
}

